package com.qiniuyun.backai.config;

import com.qiniuyun.backai.util.InSqlChatMemory;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置客户端对象
 */
@Configuration
public class CommonConfiguration {
    @Bean
    public ChatMemory getChatMemory(){
//        return new InMemoryChatMemory();
        return new InSqlChatMemory();
    }
    @Bean
    public ChatClient chatClient(ChatModel chatModel){
        // 初始化基于内存的对话记忆
        ChatMemory chatMemory = getChatMemory();
        return  ChatClient.builder(chatModel)
//                .defaultSystem("你是一名java开发工程师")
                .defaultAdvisors(  new SimpleLoggerAdvisor(),// 日志输出
                        new MessageChatMemoryAdvisor(chatMemory))
                .build();
    }
}
